home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / '92_HACK / TILEHACK / TILEHACK.C
C/C++ Source or Header  |  1992-06-18  |  24KB  |  770 lines

  1. /***************************************************************************
  2.  
  3.     TileHack, an FKEY
  4.     
  5.     A Hack that changed, and changed again. This hack is now called 
  6.      You Got No Fonts, You Skanky Programmer
  7.      
  8.     This hack uses the concept of the FKEY as a way to quickly change
  9.     your reality. Think dose, think FKEY.
  10.     
  11.     We actually use NO RESOURCES. This is essential to the self-contained
  12.     hack FKEY 'You Got No Fonts, You Skanky Programmer'.
  13.     
  14.     We want a very cool Window, made from the very stuff of code itself,
  15.     LetterForm. So we take Outline fonts, make a Picture, turn it into 
  16.     a RegionHandle with an offscreen port, write it to a resource, turn
  17.     the resource into a buncha DC.W's (the skanky programmers friend)
  18.     and embed them into the CODE itself ! (like the old days) ALL of 
  19.     this code is in the FKEY, toggled by a compile-time flag.
  20.     
  21.     When fire off the FKEY, we make a window, invisible, BlockMove the
  22.     WDEF code, STUFF the windowProc and leave the scene of the crime.
  23.     
  24.     Don't try this at home, You Skanky Programmer!
  25.     
  26.     B. Marshall Hamlin
  27.     Constructor
  28.     Noesis Sfwr Construction
  29.     
  30.     ALink: D0781
  31.     6300 Leona St
  32.     Oakland, CA  94605-1228
  33.     
  34. ***************************************************************************/
  35.                                                 //   I N C L U D E
  36. //include "LoMem.ph"
  37. #include <LoMem.h>
  38. #include <Resources.h>
  39. #include <Palettes.h>
  40.  
  41.  
  42. //*************************************************************************
  43.                                                 //   F O R W A R D
  44.  
  45. pascal void FlushCodeCache (void) = 0xA0BD;
  46.  
  47. pascal long HackWindow (short varCode, WindowPeek theWindow, short message, long param);
  48. void dataProc(void);
  49. void endData(void);
  50.  
  51. void DrawHackCont(void);
  52. void MakeRgnBg(void);
  53. RgnHandle PICT2Rgn( PicHandle p );
  54. BitMap *PICT2BitMap( PicHandle p );
  55. Boolean CreateOffscreenBitMap(GrafPtr *newOffscreen, Rect *inBounds);
  56. void DestroyOffscreenBitMap(GrafPtr oldOffscreen);
  57.  
  58. #define kWinHdrHt    98
  59. #define kWinWid        502
  60. #define kWinHt        32                            //(407-kWinHdrHt)
  61.  
  62. //*************************************************************************
  63.                                                 //   F L A G S
  64. #define NEW_WINDOW    1
  65. #define MAKE_RGN    0
  66.  
  67.  
  68. //*************************************************************************
  69.                                                 //   M A I N 
  70. main()
  71. {
  72.     SysEnvRec        environs;
  73.     GrafPtr            savPort;
  74.     OSErr            err;
  75.     WindowPeek        thWinPtr;
  76.     Ptr                wdefProcPtr;
  77.     Rect            bounds;
  78.     short            off1, off2;
  79.     long            procSize;
  80.     struct        {    short jmp ;
  81.                     ProcPtr addr ;} **wdefHdl;
  82.  
  83.     // *************************************************************
  84.     //  Insert a set of routines to build the Window Region
  85.     //  Used during development only...
  86.  
  87.     if ( MAKE_RGN) {
  88.         MakeRgnBg();
  89.         return;
  90.     }
  91.     
  92.     // *************************************************************
  93.     //  Check for color (this is a color-orinted hack!)
  94.     
  95.     err = SysEnvirons( 1, &environs);
  96.     if (err != noErr || !environs.hasColorQD)
  97.         return;
  98.  
  99.  
  100.     // *************************************************************
  101.     // Decide how big our display window is here
  102.     // Should we:
  103.     //        make it a fixed size?
  104.     //        search monitors, find a good one, calc size and put it there?
  105.     
  106.     bounds.top = (**GrayRgn).rgnBBox.top + MBarHeight + 2;
  107.     bounds.left = (**GrayRgn).rgnBBox.left + 2;
  108.     bounds.right = bounds.left + kWinWid;
  109.     bounds.bottom = bounds.top + kWinHdrHt;        // + kWinHt;
  110.  
  111.     off1 = Random();    off1 = off1 & 0x000f;
  112.     off2 = Random();    off2 = off2 & 0x000f;
  113.     
  114.     OffsetRect( &bounds, off1, off2);
  115.  
  116.     // *************************************************************
  117.     //  Make the window here. Make it invisible, so we can stuff
  118.     //  the WDEF. We could just pass a WDEF resId, but this is an 
  119.     //    FKEY  so we want to keep it _completely_ self-contained.
  120.     
  121.     thWinPtr = NewCWindow( nil, &bounds, "", false, 0, (void*)-1, true, 0L);
  122.     procSize = (long)((Ptr)endData - (Ptr)HackWindow);    // src dependent
  123.  
  124.     wdefHdl = NewHandle( procSize);
  125.     BlockMove( (Ptr)HackWindow, *wdefHdl, procSize);
  126.     
  127.     if (CPUFlag >= 2)
  128.         FlushCodeCache();
  129.     thWinPtr->windowDefProc = wdefHdl;
  130.  
  131.     GetPort( &savPort);
  132.     ShowWindow( thWinPtr);
  133.     SetPort( thWinPtr);
  134.     
  135.     // don't need it, we got SOMEBODY's A5
  136.     //asm {
  137.     //    movea.l        CurrentA5,A5
  138.     //};
  139.     
  140.     //DrawHackCont();
  141.  
  142.     // *************************************************************
  143.     //  Ditch the window ? or leave it around... TBD
  144.     
  145.     if ( 0) {
  146.         while (!Button())
  147.             ;
  148.     
  149.         SetPort( savPort);
  150.         DisposeWindow( thWinPtr);
  151.         DisposeHandle( wdefHdl);
  152.     }
  153.     
  154.     //SetPort( savPort);
  155. }
  156.  
  157. #if(0)
  158.     // *************************************************************
  159.     //  Old way. Make a Ptr, stuff the WDEF, make a handle,
  160.     //  stuff a JMP and Ptr address (don't ask me, I made it work!)
  161.     wdefProcPtr = NewPtr(procSize);
  162.     BlockMove( (Ptr)HackWindow, wdefProcPtr, procSize);
  163.     
  164.     wdefHdl = NewHandle (sizeof(**wdefHdl));
  165.     
  166.     (**wdefHdl).jmp = 0x4EF9;
  167.     (**wdefHdl).addr = wdefProcPtr;        //(**wdefHdl).addr = &HackWindow;
  168. #endif
  169.  
  170.  
  171. //*************************************************************************
  172. //        WDEF here.     NEW_WINDOW is the nifty version, not NEW is an old 
  173. //                    wave version that works (!)
  174. //*************************************************************************
  175. #define kNoGrowVar    1
  176.  
  177. pascal long HackWindow( short varCode, WindowPeek theWindow, short message, long param)
  178. {    
  179.     Handle            h, h2;
  180.     Boolean            growable;
  181.     Rect            r, bitsR;
  182.     Point            pt;
  183.     long            dataSize;
  184.     CGrafPtr        cGrafPtr;
  185.     GrafPtr            savPort;
  186.     
  187.     RGBColor    tC;
  188.     Pattern        blk = { 0,0,0,0,0,0,0,0};
  189.     Pattern        wht = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  190.     Pattern        gr  = { 0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
  191.  
  192.     
  193.     growable = (varCode != kNoGrowVar);
  194.  
  195.     switch (message) {
  196.     
  197.         case wDraw:
  198.             // ************************************************************
  199.             //                                                  DRAW
  200.             //   check the visible flag. If not visible, forget it!
  201.  
  202.             if ( !theWindow->visible)
  203.                 return;
  204.  
  205.             // ************************************************************
  206.             //   Next, check the value of param
  207.             //
  208.             //        0        Draw entire window frame
  209.             //                    check hilite
  210.             //                    check goAway flag in window record
  211.             //                    check growable flag
  212.             //        4        Handle goAway 
  213.             //
  214.             //    Note that drawing is clipped to the structure rgn
  215.             //
  216.             
  217.             if ( param == 4) {
  218.                 // no go away right now
  219.                 break;
  220.             }
  221.             
  222.             
  223. #if(NEW_WINDOW)
  224.             //PenPat( gr);
  225.             
  226.             GetPort( &savPort);                
  227.             GetCWMgrPort( &cGrafPtr);    // Most Necessary to draw in color
  228.             SetPort( cGrafPtr);
  229.             PenNormal();
  230.             
  231.             tC.red = Random();            //0x4400;
  232.             tC.green = 0x0000;
  233.             tC.blue = 0x0000;
  234.             RGBForeColor( &tC);
  235.             PaintRgn( theWindow->strucRgn);
  236.             
  237.             ForeColor( blackColor);
  238.             FrameRgn( theWindow->strucRgn);
  239.             FrameRect( &(**theWindow->contRgn).rgnBBox);
  240.             
  241.             BackColor( whiteColor);
  242.             EraseRgn( theWindow->contRgn);
  243.             
  244.             if ( theWindow->hilited) {
  245.                 Rect        r;
  246.                 short        hL;
  247.                 short        curPen;
  248.                 long        indC[ 20] = {0,1,2,3,4,5,6,12,18,24,30,215,71,218,220,221,222,223,255};
  249.                 short        *clutPtr;        // ditch the type stuff
  250.                 
  251.                 // interesting indexes in the system clut
  252.                 // 0,1,2,3,4,5,6,12,18,24,30,215,71,218,220,221,222,223,255
  253.                                 
  254.                 //DebugStr("\p;thecport");
  255.  
  256.                 //tC.red = 0x4400;
  257.                 //tC.green = 0x0000;
  258.                 //tC.blue = 0x0000;
  259.                 //RGBForeColor( &tC);
  260.                 //PaintRgn( theWindow->strucRgn);
  261.  
  262.                 // ********************************************************
  263.                 //  We want to draw in nice colors. Index2Color() FAILS
  264.                 //  So we get the colors directly from the system CLUT.
  265.                 //  FOUR shorts to each colorSpec
  266.                 
  267.                 if(0) {
  268.                     r = (**theWindow->strucRgn).rgnBBox;
  269.                     curPen = 2;
  270.                     PenSize( curPen, curPen);
  271.  
  272.                     clutPtr = &(**(**cGrafPtr->portPixMap).pmTable).ctTable;
  273.                     Debugger();
  274.  
  275.                     for( hL=0; hL<20; hL++) {
  276.                     
  277.                         Index2Color( indC[hL], &tC);
  278.                         
  279.                         //tC.red        = clutPtr[ indC[hL]+1];
  280.                         //tC.green        = clutPtr[ indC[hL]+2];
  281.                         //tC.blue        = clutPtr[ indC[hL]+3];
  282.                         
  283.                         RGBForeColor( &tC);
  284.                         MoveTo( r.left+4, r.top+58+hL*curPen);
  285.                         Line( r.right-r.left-8, 0);
  286.                         MoveTo( r.left+4, r.top+58-hL*curPen);
  287.                         Line( r.right-r.left-8, 0);
  288.                     }
  289.                     
  290.                     //PenMode( patBic);
  291.                     
  292.                     //h2 = NewHandle( 0);
  293.                     //HandAndHand( theWindow->strucRgn, h2);
  294.                     //InsetRgn( (RgnHandle)h2, -2, -2);
  295.                     //PaintRgn( (RgnHandle)h2);
  296.                 }
  297.                 
  298.             } else if ( growable) {
  299.             }
  300. #else
  301.             r = (**theWindow->strucRgn).rgnBBox;
  302.             FrameRect( &r);
  303. #endif
  304.             ForeColor( blackColor);
  305.             PenNormal();
  306.             SetPort( savPort);
  307.             
  308.             break;
  309.  
  310.  
  311.         case wHit:
  312.             // ************************************************************
  313.             //                                              HIT
  314.             
  315.             pt.v = (param & 0xFFFF0000) >> 0x10;
  316.             pt.h = param & 0x0000FFFF;
  317.             GlobalToLocal( &pt);
  318.             
  319.             if ( pt.v < kWinHdrHt)
  320.                 return wInDrag;
  321.                 
  322.             //Debugger();
  323.             if ( PtInRgn( pt, theWindow->contRgn))
  324.                 return wInContent;
  325.             
  326.             return wInGrow;
  327.             return wNoHit;
  328.             break;
  329.  
  330.  
  331.         case wCalcRgns:
  332.             // ************************************************************
  333.             //                                              CALC REGIONS
  334.  
  335.             dataSize = (long)((Ptr)endData - (Ptr)dataProc);
  336.             h = NewHandle( dataSize);
  337.             BlockMove( (Ptr)dataProc, *h, dataSize);
  338.             
  339.             r = theWindow->port.portRect;
  340.             if ( (*(CWindowRecord*)theWindow).port.portVersion < 0)  
  341.                 bitsR = (**(*(CWindowRecord*)theWindow).port.portPixMap).bounds;
  342.             else
  343.                 bitsR = theWindow->port.portBits.bounds;
  344.  
  345.             DisposeRgn( theWindow->strucRgn);
  346.             OffsetRgn( (RgnHandle)h, -bitsR.left, -bitsR.top);
  347.             theWindow->strucRgn = (RgnHandle)h;
  348.             
  349.             OffsetRect( &r, -bitsR.left, -bitsR.top);
  350.             r.top += kWinHdrHt;
  351.             r.left += 3;
  352.             r.right -= 2;
  353.             r.bottom -= 2;
  354.             OpenRgn();
  355.             FrameRect(&r);
  356.             CloseRgn( theWindow->contRgn);
  357.     
  358.             break;
  359.  
  360.  
  361.         case wNew:
  362.             // ************************************************************
  363.             //                                              NEW
  364.             break;
  365.         
  366.         case wDispose:
  367.             // ************************************************************
  368.             //                                              DISPOSE
  369.             break;
  370.         
  371.         case wGrow:
  372.             // ************************************************************
  373.             //                                              GROW
  374.             if ( growable) {
  375.                 ;
  376.             }
  377.             break;
  378.         
  379.         case wDrawGIcon:
  380.             // ************************************************************
  381.             //                                              DRAW GROW ICON
  382.             break;
  383.         
  384.         default:
  385.             break;
  386.     };
  387. }
  388.  
  389.  
  390. /********************************************************************************
  391.   dataProc
  392. *********************************************************************************/
  393.  
  394. void dataProc() 
  395. {
  396.     asm {
  397.         dc.w 0x0824,0x0000,0x0000,0x005F,0x01F7,0x0000
  398.         dc.w 0x00CA,0x00D4,0x0117,0x011D,0x7FFF,0x0001
  399.         dc.w 0x00C3,0x00CA,0x00D4,0x00DA,0x010E,0x0117
  400.         dc.w 0x011D,0x0126,0x7FFF,0x0002,0x00C0,0x00C3
  401.         dc.w 0x00DA,0x00DE,0x010A,0x010E,0x0126,0x0129
  402.         dc.w 0x7FFF,0x0003,0x00BC,0x00C0,0x00DE,0x00E1
  403.         dc.w 0x0107,0x010A,0x0129,0x012C,0x7FFF,0x0004
  404.         dc.w 0x00BB,0x00BC,0x00E1,0x00E3,0x0104,0x0107
  405.         dc.w 0x012C,0x012E,0x7FFF,0x0005,0x00B9,0x00BB
  406.         dc.w 0x00E3,0x00E5,0x0102,0x0104,0x012E,0x0130
  407.         dc.w 0x7FFF,0x0006,0x00B7,0x00B9,0x00E5,0x00E7
  408.         dc.w 0x0100,0x0102,0x0130,0x0132,0x7FFF,0x0007
  409.         dc.w 0x00B5,0x00B7,0x00E7,0x00E8,0x00FE,0x0100
  410.         dc.w 0x0132,0x0133,0x7FFF,0x0008,0x00B4,0x00B5
  411.         dc.w 0x00E8,0x00E9,0x00FD,0x00FE,0x0133,0x0134
  412.         dc.w 0x7FFF,0x0009,0x00B3,0x00B4,0x00E9,0x00EA
  413.         dc.w 0x00FB,0x00FD,0x0134,0x0135,0x7FFF,0x000A
  414.         dc.w 0x00B2,0x00B3,0x00EA,0x00EC,0x00FA,0x00FB
  415.         dc.w 0x0135,0x0136,0x7FFF,0x000B,0x00B1,0x00B2
  416.         dc.w 0x00F9,0x00FA,0x0136,0x0137,0x7FFF,0x000C
  417.         dc.w 0x00B0,0x00B1,0x00CC,0x00D1,0x00EC,0x00ED
  418.         dc.w 0x00F7,0x00F9,0x0137,0x0138,0x7FFF,0x000D
  419.         dc.w 0x00CA,0x00CC,0x00D1,0x00D3,0x00ED,0x00EE
  420.         dc.w 0x00F7,0x00F8,0x7FFF,0x000E,0x00AF,0x00B0
  421.         dc.w 0x00C9,0x00CA,0x00D3,0x00D4,0x00EE,0x00EF
  422.         dc.w 0x00F8,0x00F9,0x0138,0x0139,0x7FFF,0x000F
  423.         dc.w 0x00AE,0x00AF,0x00C8,0x00C9,0x00D4,0x00D6
  424.         dc.w 0x00EF,0x00F0,0x7FFF,0x0010,0x00AD,0x00AE
  425.         dc.w 0x00C7,0x00C8,0x00D6,0x00D7,0x00F9,0x00FA
  426.         dc.w 0x0139,0x013A,0x7FFF,0x0011,0x00F0,0x00F1
  427.         dc.w 0x00FA,0x00FB,0x010F,0x0117,0x7FFF,0x0012
  428.         dc.w 0x00AC,0x00AD,0x00C6,0x00C7,0x00D7,0x00D8
  429.         dc.w 0x010D,0x010F,0x0117,0x011A,0x7FFF,0x0013
  430.         dc.w 0x00F1,0x00F2,0x00FB,0x00FC,0x010A,0x010D
  431.         dc.w 0x011A,0x011B,0x7FFF,0x0014,0x00AB,0x00AC
  432.         dc.w 0x00D8,0x00D9,0x00FC,0x00FD,0x0108,0x010A
  433.         dc.w 0x011B,0x011C,0x7FFF,0x0015,0x00C5,0x00C6
  434.         dc.w 0x00F2,0x00F3,0x0107,0x0108,0x011C,0x011D
  435.         dc.w 0x013A,0x013B,0x7FFF,0x0016,0x00FD,0x00FE
  436.         dc.w 0x0105,0x0107,0x7FFF,0x0017,0x00AA,0x00AB
  437.         dc.w 0x00FE,0x00FF,0x0103,0x0105,0x011D,0x011E
  438.         dc.w 0x7FFF,0x0018,0x00C4,0x00C5,0x00F3,0x00F4
  439.         dc.w 0x0102,0x0103,0x7FFF,0x0019,0x00D9,0x00DA
  440.         dc.w 0x00FF,0x0102,0x7FFF,0x001A,0x013A,0x013B
  441.         dc.w 0x7FFF,0x001B,0x00A9,0x00AA,0x7FFF,0x001D
  442.         dc.w 0x00F4,0x00F5,0x7FFF,0x001F,0x011D,0x011E
  443.         dc.w 0x7FFF,0x0020,0x0139,0x013A,0x7FFF,0x0021
  444.         dc.w 0x0000,0x00A9,0x00C4,0x00DA,0x00F5,0x011D
  445.         dc.w 0x0139,0x01F7,0x7FFF,0x0022,0x0001,0x00A9
  446.         dc.w 0x00C4,0x00DA,0x00F5,0x011C,0x0138,0x01F6
  447.         dc.w 0x7FFF,0x0023,0x0002,0x00A9,0x00C4,0x00DA
  448.         dc.w 0x00F5,0x011C,0x0138,0x01F5,0x7FFF,0x0025
  449.         dc.w 0x0004,0x00AA,0x00C5,0x00D9,0x00F4,0x011B
  450.         dc.w 0x0137,0x01F3,0x7FFF,0x0026,0x00C5,0x00C6
  451.         dc.w 0x011A,0x011B,0x7FFF,0x0027,0x00AA,0x00AB
  452.         dc.w 0x00D8,0x00D9,0x0136,0x0137,0x7FFF,0x0028
  453.         dc.w 0x0119,0x011A,0x0135,0x0136,0x7FFF,0x0029
  454.         dc.w 0x00C6,0x00C7,0x00D7,0x00D8,0x0118,0x0119
  455.         dc.w 0x7FFF,0x002A,0x00AB,0x00AC,0x00C7,0x00C8
  456.         dc.w 0x0134,0x0135,0x7FFF,0x002B,0x00AC,0x00AD
  457.         dc.w 0x00C8,0x00C9,0x00D6,0x00D7,0x0117,0x0118
  458.         dc.w 0x0133,0x0134,0x7FFF,0x002C,0x00C9,0x00CA
  459.         dc.w 0x00D4,0x00D6,0x00F3,0x00F4,0x0116,0x0117
  460.         dc.w 0x7FFF,0x002D,0x00AD,0x00AE,0x00CA,0x00CD
  461.         dc.w 0x00D1,0x00D4,0x0132,0x0133,0x7FFF,0x002E
  462.         dc.w 0x00AE,0x00AF,0x00CD,0x00D1,0x0115,0x0116
  463.         dc.w 0x0131,0x0132,0x7FFF,0x002F,0x00AF,0x00B0
  464.         dc.w 0x00F2,0x00F3,0x0114,0x0115,0x0130,0x0131
  465.         dc.w 0x7FFF,0x0030,0x00B0,0x00B1,0x0113,0x0114
  466.         dc.w 0x7FFF,0x0031,0x00B1,0x00B2,0x0112,0x0113
  467.         dc.w 0x012F,0x0130,0x7FFF,0x0032,0x0070,0x0077
  468.         dc.w 0x007E,0x0085,0x008D,0x0092,0x009F,0x00A3
  469.         dc.w 0x00B2,0x00B3,0x00F1,0x00F2,0x0111,0x0112
  470.         dc.w 0x012E,0x012F,0x0141,0x0146,0x014C,0x0151
  471.         dc.w 0x0158,0x015D,0x016A,0x016E,0x0173,0x0178
  472.         dc.w 0x017C,0x017E,0x7FFF,0x0033,0x0077,0x0078
  473.         dc.w 0x009C,0x009F,0x00A3,0x00A6,0x00B3,0x00B5
  474.         dc.w 0x012D,0x012E,0x0167,0x016A,0x016E,0x0171
  475.         dc.w 0x017B,0x017C,0x017E,0x0181,0x7FFF,0x0034
  476.         dc.w 0x007D,0x007E,0x0092,0x0093,0x009B,0x009C
  477.         dc.w 0x00A5,0x00A6,0x00B5,0x00B6,0x00F0,0x00F1
  478.         dc.w 0x0110,0x0111,0x012C,0x012D,0x015D,0x015E
  479.         dc.w 0x0166,0x0167,0x0170,0x0171,0x0180,0x0181
  480.         dc.w 0x7FFF,0x0035,0x008C,0x008D,0x009A,0x009B
  481.         dc.w 0x00B6,0x00B8,0x010F,0x0110,0x012B,0x012C
  482.         dc.w 0x0157,0x0158,0x0165,0x0166,0x017A,0x017B
  483.         dc.w 0x017F,0x0180,0x7FFF,0x0036,0x0078,0x0079
  484.         dc.w 0x0099,0x009A,0x009F,0x00A5,0x00B8,0x00BB
  485.         dc.w 0x00EF,0x00F0,0x010E,0x010F,0x012A,0x012B
  486.         dc.w 0x0164,0x0165,0x016A,0x0170,0x017E,0x017F
  487.         dc.w 0x7FFF,0x0037,0x007C,0x007D,0x0093,0x0094
  488.         dc.w 0x009E,0x009F,0x00BB,0x00BE,0x010D,0x010E
  489.         dc.w 0x0129,0x012A,0x015E,0x015F,0x0169,0x016A
  490.         dc.w 0x0179,0x017A,0x7FFF,0x0038,0x008B,0x008C
  491.         dc.w 0x008E,0x0090,0x0098,0x0099,0x009D,0x009E
  492.         dc.w 0x00BE,0x00C2,0x00D0,0x00D4,0x00EE,0x00EF
  493.         dc.w 0x010C,0x010D,0x0128,0x0129,0x0146,0x014C
  494.         dc.w 0x0156,0x0157,0x0159,0x015B,0x0163,0x0164
  495.         dc.w 0x0168,0x0169,0x0178,0x0179,0x017D,0x017E
  496.         dc.w 0x7FFF,0x0039,0x0074,0x0075,0x0079,0x007A
  497.         dc.w 0x007F,0x0080,0x00C2,0x00D0,0x010B,0x010C
  498.         dc.w 0x017C,0x017D,0x7FFF,0x003A,0x007B,0x007C
  499.         dc.w 0x008A,0x008B,0x0094,0x0095,0x00D3,0x00D4
  500.         dc.w 0x00ED,0x00EE,0x010A,0x010B,0x0127,0x0128
  501.         dc.w 0x0155,0x0156,0x015F,0x0160,0x017C,0x017D
  502.         dc.w 0x7FFF,0x003B,0x0075,0x0076,0x008D,0x008E
  503.         dc.w 0x0090,0x0091,0x00EC,0x00ED,0x0109,0x010A
  504.         dc.w 0x0126,0x0127,0x0146,0x014C,0x0158,0x0159
  505.         dc.w 0x015B,0x015C,0x017D,0x017E,0x7FFF,0x003C
  506.         dc.w 0x007A,0x007B,0x007E,0x007F,0x008D,0x0091
  507.         dc.w 0x0095,0x0096,0x0098,0x0099,0x00D2,0x00D3
  508.         dc.w 0x0108,0x0109,0x0125,0x0126,0x0158,0x015C
  509.         dc.w 0x0160,0x0161,0x0163,0x0164,0x0178,0x0179
  510.         dc.w 0x7FFF,0x003D,0x0089,0x008A,0x009D,0x009E
  511.         dc.w 0x00D1,0x00D2,0x00EB,0x00EC,0x0107,0x0108
  512.         dc.w 0x0124,0x0125,0x0154,0x0155,0x0168,0x0169
  513.         dc.w 0x0179,0x017A,0x017E,0x017F,0x7FFF,0x003E
  514.         dc.w 0x0076,0x0077,0x007D,0x007E,0x009E,0x009F
  515.         dc.w 0x00EA,0x00EB,0x0106,0x0107,0x0123,0x0124
  516.         dc.w 0x0169,0x016A,0x017F,0x0180,0x7FFF,0x003F
  517.         dc.w 0x0088,0x0089,0x008C,0x0092,0x0096,0x0097
  518.         dc.w 0x0099,0x009A,0x009F,0x00A5,0x00D0,0x00D1
  519.         dc.w 0x0105,0x0106,0x0122,0x0123,0x0153,0x0154
  520.         dc.w 0x0157,0x015D,0x0161,0x0162,0x0164,0x0165
  521.         dc.w 0x016A,0x0170,0x017A,0x017B,0x0180,0x0181
  522.         dc.w 0x7FFF,0x0040,0x009A,0x009B,0x00CF,0x00D0
  523.         dc.w 0x00E9,0x00EA,0x0104,0x0105,0x0121,0x0122
  524.         dc.w 0x0165,0x0166,0x7FFF,0x0041,0x0077,0x0078
  525.         dc.w 0x007C,0x007D,0x008B,0x008C,0x009B,0x009D
  526.         dc.w 0x00A5,0x00A6,0x00CE,0x00CF,0x00E8,0x00E9
  527.         dc.w 0x0103,0x0104,0x0120,0x0121,0x0156,0x0157
  528.         dc.w 0x0166,0x0168,0x0170,0x0171,0x017B,0x017C
  529.         dc.w 0x0181,0x0182,0x7FFF,0x0042,0x0087,0x0088
  530.         dc.w 0x0092,0x0093,0x0097,0x0098,0x009D,0x00A0
  531.         dc.w 0x00A4,0x00A6,0x00CD,0x00CE,0x00E7,0x00E8
  532.         dc.w 0x0102,0x0103,0x011F,0x0120,0x0152,0x0153
  533.         dc.w 0x015D,0x015E,0x0162,0x0163,0x0168,0x016B
  534.         dc.w 0x016F,0x0171,0x017C,0x017D,0x017F,0x0182
  535.         dc.w 0x7FFF,0x0043,0x0070,0x0074,0x0078,0x007C
  536.         dc.w 0x0080,0x0085,0x0087,0x008B,0x0093,0x0098
  537.         dc.w 0x00A0,0x00A4,0x00CC,0x00CD,0x00E6,0x00E7
  538.         dc.w 0x0101,0x0102,0x011E,0x011F,0x0141,0x0146
  539.         dc.w 0x014C,0x0151,0x0152,0x0156,0x015E,0x0163
  540.         dc.w 0x016B,0x016F,0x0173,0x0178,0x017D,0x017F
  541.         dc.w 0x7FFF,0x0044,0x00CB,0x00CC,0x00E5,0x00E6
  542.         dc.w 0x0100,0x0101,0x011D,0x011E,0x7FFF,0x0045
  543.         dc.w 0x00CA,0x00CB,0x00E4,0x00E5,0x00FF,0x0100
  544.         dc.w 0x011C,0x011D,0x7FFF,0x0046,0x00C8,0x00CA
  545.         dc.w 0x00E3,0x00E4,0x00FE,0x00FF,0x011B,0x011C
  546.         dc.w 0x7FFF,0x0047,0x00C7,0x00C8,0x00E2,0x00E3
  547.         dc.w 0x00FD,0x00FE,0x011A,0x011B,0x7FFF,0x0048
  548.         dc.w 0x00C5,0x00C7,0x00E1,0x00E2,0x00FC,0x00FD
  549.         dc.w 0x0119,0x011A,0x7FFF,0x0049,0x00C4,0x00C5
  550.         dc.w 0x00E0,0x00E1,0x00FA,0x00FC,0x0119,0x013C
  551.         dc.w 0x7FFF,0x004A,0x00C2,0x00C4,0x00DF,0x00E0
  552.         dc.w 0x00F9,0x00FA,0x7FFF,0x004B,0x00C0,0x00C2
  553.         dc.w 0x00DE,0x00DF,0x00F8,0x00F9,0x7FFF,0x004C
  554.         dc.w 0x00BE,0x00C0,0x00DC,0x00DE,0x00F7,0x00F8
  555.         dc.w 0x7FFF,0x004D,0x00BC,0x00BE,0x00DB,0x00DC
  556.         dc.w 0x00F6,0x00F7,0x7FFF,0x004E,0x00B9,0x00BC
  557.         dc.w 0x00D9,0x00DB,0x00F5,0x00F6,0x7FFF,0x004F
  558.         dc.w 0x00B5,0x00B9,0x00D8,0x00D9,0x00F4,0x00F5
  559.         dc.w 0x7FFF,0x0050,0x00B1,0x00B5,0x00D7,0x00D8
  560.         dc.w 0x7FFF,0x0051,0x00D5,0x00D7,0x7FFF,0x0052
  561.         dc.w 0x00D3,0x00D5,0x7FFF,0x0053,0x00D1,0x00D3
  562.         dc.w 0x7FFF,0x0054,0x00CF,0x00D1,0x7FFF,0x0055
  563.         dc.w 0x00CD,0x00CF,0x7FFF,0x0056,0x00CB,0x00CD
  564.         dc.w 0x7FFF,0x0057,0x00C8,0x00CB,0x7FFF,0x0058
  565.         dc.w 0x00C5,0x00C8,0x7FFF,0x0059,0x00C2,0x00C5
  566.         dc.w 0x7FFF,0x005A,0x00BF,0x00C2,0x00F4,0x00F5
  567.         dc.w 0x7FFF,0x005B,0x0004,0x00B1,0x00BF,0x00F5
  568.         dc.w 0x013C,0x01F3,0x7FFF,0x005D,0x0002,0x01F5
  569.         dc.w 0x7FFF,0x005E,0x0001,0x01F6,0x7FFF,0x005F
  570.         dc.w 0x0000,0x01F7,0x7FFF,0x7FFF
  571.     };
  572. }
  573.  
  574. void endData()
  575. {
  576.     ;
  577. }
  578.  
  579.  
  580.  
  581.  
  582. /********************************************************************************
  583.   MakeRgnBg
  584.  
  585. *********************************************************************************/
  586. void MakeRgnBg()
  587. {
  588.     PicHandle        p;
  589.     RgnHandle        r;
  590.     short            resFileID;
  591.  
  592.     Debugger();
  593.     p = (Handle)GetResource( 'PICT', 1024);
  594.     r = PICT2Rgn( p);
  595.     CreateResFile( "\ptemp");
  596.     resFileID = OpenResFile( "\ptemp");
  597.     AddResource( (Handle)r, 'tRgn', 1024, "\pwinBg");
  598.     WriteResource( (Handle)r);
  599.     CloseResFile( resFileID);
  600.     return;
  601. }
  602.  
  603. /********************************************************************************
  604.   PICT2Rgn
  605.   
  606.       Using a PicHandle, create the region (1 bit) described by the drawn PICT.
  607.      At present, make no adjustment for PICT frame.
  608.      
  609.      Must work on a 68k !! 
  610.  
  611. *********************************************************************************/
  612. RgnHandle    PICT2Rgn( PicHandle p )
  613. {
  614.     GrafPtr            aGP;
  615.     GrafPtr            savPort;
  616.     Rect            gpRect;
  617.     OSErr            err;
  618.     BitMap            *resBM;
  619.     RgnHandle        rH;
  620.  
  621.     if(!p) return 0;
  622.     
  623.     gpRect = (**p).picFrame;
  624.     
  625.     rH = NewRgn();
  626.     
  627.     //if ( TrapAvailable( 0xA8D7)) {
  628.         if ( CreateOffscreenBitMap( &aGP, &gpRect ) ) {
  629.             //CheckAllocation( resBM=(BitMap*)NewPtr( sizeof(BitMap)));
  630.             resBM=(BitMap*)NewPtr( sizeof(BitMap));
  631.             GetPort( &savPort);        
  632.             SetPort( aGP);
  633.             DrawPicture( p, &gpRect);
  634.                                             /* Bad news iff aGP is a color port */
  635.             *resBM = aGP->portBits;
  636.     
  637.             if ( err = BitMapToRegion( rH, resBM)) {
  638.                 DisposeRgn( rH );
  639.                 rH = 0;
  640.             }
  641.     
  642.               ClosePort( aGP);
  643.             DisposPtr( (Ptr)aGP);
  644.     
  645.             //gError->CheckOSError( err = QDError());
  646.             DisposPtr( resBM->baseAddr);
  647.             DisposPtr( (Ptr)resBM);
  648.             SetPort( savPort);
  649.         } else {
  650.             DisposeRgn( rH);
  651.             rH = 0;
  652.         }
  653.     //} else {
  654.     //    OpenRgn();
  655.     //    FrameRect( &gpRect);
  656.     //    CloseRgn( rH);
  657.     //}
  658.     
  659.     return rH;
  660. }
  661.  
  662.  
  663. /********************************************************************************
  664.   PICT2BitMap
  665.   
  666. *********************************************************************************/
  667. BitMap    *PICT2BitMap( PicHandle p )
  668. {
  669.     GrafPtr            aGP;
  670.     GrafPtr            savPort;
  671.     Rect            gpRect;
  672.     BitMap            *resBM;
  673.     
  674.     if(!p) return 0;
  675.     resBM = (BitMap *)NewPtr( sizeof( BitMap ));
  676.     //CheckAllocation( resBM = (BitMap *)NewPtr( sizeof( BitMap ) ) );
  677.     
  678.     gpRect = (**p).picFrame;
  679.     if ( CreateOffscreenBitMap( &aGP, &gpRect ) ) {
  680.  
  681.         GetPort( &savPort );        SetPort( aGP );
  682.         DrawPicture( p, &gpRect );
  683.                                         /* Bad news iff really color port */
  684.         *resBM = aGP->portBits;
  685.           ClosePort(aGP);
  686.         DisposPtr((Ptr)aGP);
  687.         SetPort( savPort );
  688.     } else {
  689.         resBM->baseAddr = 0;
  690.         resBM->rowBytes = 0;
  691.         SetRect( &resBM->bounds, 0, 0, 0, 0 );
  692.     }
  693.     
  694.     return resBM;
  695. }
  696.  
  697.  
  698.  
  699. /********************************************************************************
  700.   CreateOffscreenBitMap
  701.                               from DTS TechNote #41
  702. *********************************************************************************/
  703. Boolean CreateOffscreenBitMap(GrafPtr *newOffscreen, Rect *inBounds)
  704. {
  705.   GrafPtr savePort;
  706.   GrafPtr newPort;
  707.  
  708.   GetPort(&savePort);    /* need this to restore thePort after OpenPort */
  709.  
  710.   newPort = (GrafPtr) NewPtr(sizeof(GrafPort));    /* allocate the grafPort */
  711.   if (MemError() != noErr)
  712.     return false;                 /* failed to allocate the off-screen port */
  713.  
  714.   /*
  715.   the call to OpenPort does the following . . . 
  716.     allocates space for visRgn (set to screenBits.bounds)
  717.     and clipRgn (set wide open)
  718.     sets portBits to screenBits
  719.     sets portRect to screenBits.bounds
  720.     etc. (see IM I-163,164)
  721.     side effect: does a SetPort(&offScreen)
  722.   */
  723.   OpenPort(newPort);
  724.   /* make bitmap the size of the bounds that caller supplied */
  725.   newPort->portRect = *inBounds;
  726.   newPort->portBits.bounds = *inBounds;
  727.   RectRgn(newPort->clipRgn, inBounds);/* avoid wide-open clipRgn, to be safe  */
  728.   RectRgn(newPort->visRgn, inBounds); /* in case newBounds is > screen bounds */
  729.  
  730.   /*rowBytes is size of row, it must be rounded up to an even number of bytes*/
  731.   newPort->portBits.rowBytes =
  732.            ((inBounds->right - inBounds->left + 15) >> 4) << 1;
  733.  
  734.   /* number of bytes in BitMap is rowBytes * number of rows */
  735.   /* see notes at end of Technical Note about using _NewHandle
  736.      rather than _NewPtr */
  737.   newPort->portBits.baseAddr =
  738.            NewPtr(newPort->portBits.rowBytes * (long)
  739.            (inBounds->bottom - inBounds->top));
  740.   if (MemError()!=noErr) { /* check to see if we had enough room for the bits */
  741.     SetPort(savePort);
  742.     ClosePort(newPort);      /* dump the visRgn and clipRgn */
  743.     DisposPtr((Ptr)newPort); /* dump the GrafPort */
  744.     return false;            /* tell caller we failed */
  745.     }
  746.   /* since the bits are just memory, let's clear them before we start */
  747.   EraseRect(inBounds);     /* OpenPort did a SetPort(newPort) so we are ok */
  748.   *newOffscreen = newPort;
  749.   SetPort(savePort);
  750.   return true;               /* tell caller we succeeded! */
  751. }
  752.  
  753.  
  754. /********************************************************************************
  755.   DestroyOffscreenBitMap
  756.                               from DTS TechNote #41
  757. *********************************************************************************/
  758.  
  759. void DestroyOffscreenBitMap(GrafPtr oldOffscreen)
  760. {
  761.   ClosePort(oldOffscreen);                     /* dump the visRgn and clipRgn */
  762.   DisposPtr(oldOffscreen->portBits.baseAddr);  /* dump the bits */
  763.   DisposPtr((Ptr)oldOffscreen);                /* dump the port */
  764. }
  765.  
  766.  
  767.  
  768.  
  769. //**************************************************************************
  770.                                             //  E N D   O F  L I S T I N G